package org.web.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springside.modules.security.utils.Digests;
import org.springside.modules.utils.Encodes;
import org.web.dao.WebDAO;
import org.web.domain.*;

import java.util.List;

/**
 * @Author:芯古子
 * @Date:2022/4/17 15:24
 **/
@Service(value = "wenZhangService")
public class WenZhangServiceimpl implements WenZhangService {
    public static final String HASH_ALGORITHM = "SHA-1";
    public static final int HASH_INTERATIONS = 1024;
    private static final int SALT_SIZE = 8;
    @Autowired
    private WebDAO dao;
    @Override
    public List<XinWen> xin() {
        List<XinWen> xin = dao.xin();
        return xin;
    }

    @Override
    public void delete(String title) {
        dao.delete(title);
    }

    @Override
    public void add2(XinWen xinWen) {
        dao.add(xinWen);
    }

    @Override
    public void up2(XinWen xinWen) {
        dao.up1(xinWen);
    }

    @Override
    public void upa2(String title) {
        dao.upa(title);
    }

    @Override
    public List<XinWen> key2(String title,Integer id,String matter) {
        List<XinWen> key = dao.key(title,id,matter);
        return key;
    }

    @Override
    public PageBean<XinWen> pageQuery(int currentPage, int PageSize,Integer classid,String title) {
        PageBean<XinWen> pb = new PageBean<>();

        //设置当前页数
        pb.setCurrentPage(currentPage);

        //每页展示条数
        pb.setPageSize(PageSize);

        //总条数
        int total = dao.total(classid,title);
        pb.setTotalCount(total);

        //设置当前页显示的数据集合
        int start=(currentPage-1)*PageSize;

        List<XinWen> list = dao.findelse(start, PageSize,classid,title);
        pb.setList(list);


        //设置总页数=总条数/每页展示条数
        int totalPage=total%PageSize==0?total/PageSize:(total/PageSize)+1;
        pb.setTotalPage(totalPage);
        return pb;
    }
//查询分类标签
    @Override
    public List<Classify> selectClassName() {
        List<Classify> classify = dao.selectClassName();
        return classify;
    }

    @Override
    public void watch(Integer id) {
        dao.watch(id);
        System.out.println("service");
    }

    @Override
    public void support(Integer id) {
        dao.suport(id);
    }

    @Override
    public void support2(Integer id) {
        dao.suport2(id);
    }

    @Override
    public List<Sui> all() {
        List<Sui> all = dao.all();
        return all;
    }

    @Override
    public void del(String time) {
        dao.del(time);
    }

    @Override
    public void upa(String time) {
        dao.upda(time);
    }

    @Override
    public void up(Sui sui) {
        dao.upda2(sui);
    }

    @Override
    public void add(Sui sui) {
        dao.addsui(sui);
    }

    @Override
    public List<XinWen> pai() {
        List<XinWen> pai = dao.pai();
        return pai;
    }

    @Override
    public List<XinWen> pai2() {
        List<XinWen> xinWens = dao.pai2();
        return xinWens;
    }

    @Override
    public XinWen shang(Integer id) {
        int i = dao.total2();
        XinWen shang = dao.shang(id);
        shang.setLength(i);
        return shang;
    }

    @Override
    public XinWen xia(Integer id) {
        int i = dao.total2();
        XinWen shang = dao.xia(id);
        shang.setLength(i);
        return shang;
    }

    @Override
    public User selectUser(String loginName) {
        User user = dao.selectUser(loginName);
        return user;
    }

}
